#include<bits/stdc++.h>
using namespace std;
int n, m;
int op = 0;
vector<pair<int, int> > ans;
int a[400005], b[400005];
bool no(int x, int y){
    if(1 <= x && x <= n && 1 <= y && y <= m){
        if(a[x+y] || b[x-y+m])return 0;
        return 1;
    }
    return 0;
}
signed main(){
    freopen("bishop.in", "r", stdin);
    freopen("bishop.out", "w", stdout);
    cin >> n >> m;
    if(n > m)swap(n, m), op = 1;
    if(n > 1){
        for(int i = 1; i <= m; i += n * 2-2){
            for(int j = 1; j < n && i + j - 1 <= m; j++){
                ans.emplace_back(1, i + j - 1);
                ans.emplace_back(n, i + j - 1);
            }
        }
        for(auto [i, j] : ans){
            a[i+j] = 1;
            b[i-j+m] = 1;
        }
        int x = (n+1>>1), y = m;
        while(!no(x, y) && y >= 1)y--;
        if(y >= 1){
            while(no(x-1, y) && x > 1)x--;
            while(no(x - 1, y - 1))x--, y--;
            if(no(x, y - 1)){
                for(int i = x; i <= n - x + 1; i += 2){
                    ans.emplace_back(i, y - 1);
                    ans.emplace_back(i, y);
                }
            }else{
                for(int i = x; i <= n - x + 1; i++){
                    ans.emplace_back(i, y);
                }
            }
        }
    }else{
        for(int i = 1; i <= m; i++){
            ans.emplace_back(1, i);
        }
    }
    cout << ans.size() << endl;
    for(auto [x, y] : ans){
        if(op == 1)printf("%d %d\n", y, x);
        else printf("%d %d\n", x, y);
    }
    return 0;
}